package com.joker.microstoremanager.service.base;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.io.Serializable;
import java.util.List;


public abstract class BaseService<T, ID extends Serializable> {

    protected JpaRepository<T, ID> repository;

    public void setRepository(JpaRepository<T, ID> repository) {
        this.repository = repository;
    }


    public T save(T o){
        return repository.save(o);
    }

    public Iterable<T> save(Iterable<T> o){
        return repository.save(o);
    }

    public void delete(T o){
        repository.delete(o);
    }

    public void delete(ID id){
        repository.delete(id);
    }

    public List<T> findAll(){
        return repository.findAll();
    }

    public Page<T> findAll(Pageable pageable){
        return repository.findAll(pageable);
    }
}
